package course.web;
import course.domain.Personal;
import course.domain.*;


import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import course.repository.PersonalRepository;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/personal")
@SessionAttributes("personal")
public class PersonalController{
	
	@ModelAttribute(name = "personal")
	  public Personal design() {
	    return new Personal();
	  }
	
	@GetMapping
	public String personalForm(Model model) {
		return "personal";
	}
	@PostMapping
	public String processPersoninfo(@Valid @ModelAttribute("personal") Personal personal,Errors errors,Model model) {
		if(errors.hasErrors()) {
			 return "personal";
		 }
		Personal saved =(Personal) model.getAttribute("personal");;
		log.info("个人信息:"+personal);
		log.info("个人信息:"+saved);
		return "redirect:/selection";
	}
	
	
}
